/***************************************************************************
 *   Copyright (C) 2009 by Marian Skvarek   *
 *   skvarek.marian@gmail.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A TrackICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef EASYSCORE_CORECBAR_H
#define EASYSCORE_CORECBAR_H

#include "CTrack.h"

#include <QLinkedList>

namespace easyscore
{
	namespace core
	{
		class CScore;
		class CPart;
		class CSymbol;
		class CNoteGroup;
		class CPause;
		class CBarView;

		/**
			Bar model
			@author Marian Skvarek <skvarek.marian@gmail.com>
		*/
		class CBar
		{
//Members
			protected:
				QLinkedList<CSymbol *> mSymbols;
                                bool mActive;
				CTrack *mParentTrack;
				CNoteGroup *mTempNoteGroup;

				CBarView *mView;

//Accessors
			public:
                                QLinkedList<CSymbol *> &getSymbols() { return mSymbols; }
                                void setActive(bool value) { mActive = value; }
                                bool getActive() { return mActive; }
				CTrack *getParentTrack() { return mParentTrack; }
				CPart *getParentPart() { return mParentTrack->getParentPart(); }
				CScore *getParentScore() { return mParentTrack->getParentScore(); }
				
				bool hasTempNoteGroup() { return mTempNoteGroup != 0; }
				
				CBarView *getView() { return mView; }

//Constructors,Destructors and Initialization
			public:
				CBar( CTrack *parentTrack = 0);
				void initialize();
				
				void clear();
				~CBar();

//Public methods
			public:
                                void insertSymbol(CSymbol *symbol,CSymbol *before = 0);
				void removeSymbol(CSymbol *symbol);
				void replaceSymbol(CSymbol *symbol, CSymbol *replacement);
                                void insertTemporaryNoteGroup(CPause *underlyingPause);
                                void removeNoteGroup(CNoteGroup *noteGroupToRemove);
				void removeTemporaryNoteGroup();
				void confirmTemporaryNoteGroup();
				void unionRests();
				void splitRests();
				void splitRests(NOTE_VALUE currentValue);
                                void clearSymbols();
				
				bool hasView() { return mView != 0; }
				void createView();
				void destroyView();
				void suspendView();
				void resumeView();

	
				
//Protected methods
			protected:
				CPause *createPause(NOTE_VALUE value);

				QLinkedList<CSymbol *>::iterator getIterator(CSymbol *symbol);
				void appendRests(NOTE_VALUE totalValue,NOTE_VALUE maxPauseValue, QLinkedList<CSymbol *> &symbolList );
				
				void updateView();
				
				
//Private methods
			private:
				
		};
	}//namespace core
}//namespace easyscore

#endif
